$(document).ready(function () {
    $("#navigation").treeview({
        persist: "location",
        collapsed: true,
        unique: true
    });
});

function ShowListItems(listEncodedAsJson) {
    AjaxCall("Home", "LoadListItems", listEncodedAsJson, "main-view");
}

function ShowListItemProperties(listItemEncodedAsJson) {
    AjaxCall("Home", "LoadListItemProperties", listItemEncodedAsJson, "main-sub-view");
}

function AjaxCall(controllerName, actionName, json, divToAlter) {
    $.ajax({
        type: "POST",
        url: "/" + controllerName + "/" + actionName,
        dataType: 'json',
        data: json,
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            $("#"+divToAlter).html(result.partialhtml);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $("#"+divToAlter).html(errorThrown);
        }
    });
}